import React, { memo, useCallback } from 'react'
import { Pagination } from 'antd'
import { PaginationWrapper } from './style'
import proptypes from 'prop-types'
import { scrollAnimation } from '@/utils/scroll'

function B_Pagination(props) {
  const { total, defaultPageSize, current, handleChange } = props

  const dealChange = useCallback(
    (page, pageSize) => {
      handleChange(page, pageSize)
      scrollAnimation(window.scrollY, window.innerHeight - 20)
    },
    [handleChange]
  )

  return (
    <PaginationWrapper className="base-bgc">
      <Pagination
        current={current}
        total={total}
        defaultPageSize={defaultPageSize}
        hideOnSinglePage={true}
        onChange={dealChange}
      />
    </PaginationWrapper>
  )
}

B_Pagination.propTypes = {
  total: proptypes.number,
  current: proptypes.number,
  defaultPageSize: proptypes.number,
  handleChange: proptypes.func
}

export default memo(B_Pagination)
